package com.pyk.service.impl;

import com.pyk.entity.Question;
import com.pyk.entity.QuestionType;
import com.pyk.exception.GlobalExceptionHandler;
import com.pyk.mapper.QuestionTypeMapper;
import com.pyk.service.QuestionTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PatchMapping;

import java.util.List;

@Service
public class QuestionTypeServiceImpl implements QuestionTypeService {

    @Autowired
    private QuestionTypeMapper questionTypeMapper;

    public void add(QuestionType questionType) {

        List<QuestionType> list=questionTypeMapper.selectByName(questionType.getName());
        if(list.size()>0){
            throw new RuntimeException("题型名称不能相同");
        }
        questionTypeMapper.insert(questionType);
    }

    public void updateById(QuestionType questionType) {
        questionTypeMapper.updateById(questionType);
    }

    public void deleteById(int id) {
        questionTypeMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            questionTypeMapper.deleteById(id);
        }
    }

    public QuestionType findById(int id) {
        return questionTypeMapper.selectById(id);
    }

    public List<QuestionType> findAll(QuestionType questionType) {
        return questionTypeMapper.selectAll(questionType);
    }

//    public PageInfo<QuestionType> selectPage(QuestionType questionType, Integer pageNum, Integer pageSize) {
//        PageHelper.startPage(pageNum, pageSize);
//        List<QuestionType> lsit = questionTypeMapper.selectAll(questionType);
//        return PageInfo.of(lsit);
//    }
}